package com.logger;

import com.fmk.utils.RegExpUtils;

/**
 * 
 * @author bbarhoumi
 * 
 */
public enum EnumUserLogLineType {
    UNKNOWN("UNKNOWN"),
    QUERY_START_1(RegExpUtils.Constants.REGX_REQUEST_PREPARE_QUERY_NAME),
    QUERY_EXECUTE(RegExpUtils.Constants.REGX_INFO_REQUEST_EXECUTE_QUERY_NAME),
    QUERY_START_2(RegExpUtils.Constants.REGX_INFO_REQUEST_EXECUTE_QUERY),
    QUERY_CONSTRUCTION_TIME(RegExpUtils.Constants.REGX_CONSTRUCTION_TIME),
    QUERY_CONSTRUCTION_TIME_EXECUTION_TIME_ROWS_NUMBER(RegExpUtils.Constants.REGX_CONSTRUCTION_TIME_EXECUTION_TIME_ROWS_NUMBER),
    QUERY_ROWS_NUMBER_ELAPSED_TIME(RegExpUtils.Constants.REGX_ROWS_NUMBER_ELAPSED_TIME),
    QUERY_ROWS_NUMBER_AFFECTED(RegExpUtils.Constants.REGX_ROWS_NUMBER_AFFECTED),
    QUERY_ELAPSED_TIME(RegExpUtils.Constants.REGX_ELAPSED_TIME),
    QUERY_RAW_QUERY(RegExpUtils.Constants.REGX_RAW_QUERY),
    TRANSACTION_BEGIN(RegExpUtils.Constants.REGX_BEGIN_TRANSACTION),
    TRANSACTION_COMMIT(RegExpUtils.Constants.REGX_COMMIT_TRANSACTION),
    TRANSACTION_ROLL_BACK(RegExpUtils.Constants.REGX_ROLL_BACK_TRANSACTION);
    private final String regx;

    private EnumUserLogLineType(final String regx) {
        this.regx = regx;
    }

    public static EnumUserLogLineType getLineType(final String line) {
        for (final EnumUserLogLineType value : EnumUserLogLineType.values()) {
            final boolean isMatchFound = RegExpUtils.isMatchFound(line, value.regx);
            if (isMatchFound) {
                return value;
            }
        }
        return UNKNOWN;
    }

}